import requests
import json
import time
from pprint import pprint
# 单次提取测试

xml = '''
<configuration>
  <property>
    <name>oozie.wf.application.path</name>
    <value>hdfs://localcluster/user/hue/oozie/workspaces/hue-oozie-1578979482.24</value>
  </property>
  <property>
    <name>oozie.use.system.libpath</name>
    <value>True</value>
  </property>
  <property>
    <name>user.name</name>
    <value>qhy</value>
  </property>
  <property>
    <name>jobTracker</name>
    <value>rm1</value>
  </property>
  <property>
    <name>mapreduce.job.user.name</name>
    <value>qhy</value>
  </property>
  <property>
    <name>nameNode</name>
    <value>hdfs://localcluster</value>
  </property>
  <property>
    <name>outArgs</name>
    <value>%s</value>
  </property>
</configuration>
'''

HEADER = {
    'User-Agent':
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
    'Content-Type':
    'application/xml;charset=UTF-8',
}
# r = requests.get('http://hadoop2x-06:12000/oozie/versions')
# print(r.text)
dicArgs = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
    'Content-Type':'application/xml;charset=UTF-8',
    'hello':'world'
}
# r = requests.post(
#     'http://hadoop2x-06:12000/oozie/v1/jobs?action=start', data=xml % json.dumps(dicArgs), headers=HEADER)
# print(r.text)
# jobid = json.loads(r.text, encoding='utf8')['id']
#url = 'http://hadoop2x-06:12000/oozie/v1/job/%s?show=info&timezone=GMT' % jobid
url = 'http://hadoop2x-06:12000/oozie/v1/job/%s?show=info&timezone=GMT' % "000008-191012235641226-oozie-vipc-W"

while True:
    time.sleep(5)
    r = requests.get(url)
    pprint("********************************")
    pprint(r.text)
    pprint("********************************")
    pprint(type(r.text))
    pprint(("********************************"))
    pprint(json.loads(r.text)["status"])
    pprint("************************************")
